#!/bin/bash
# spt.sh start/stop

# 1、判断参数是否传入
if [ $# -lt 1 ]; then
    echo "必须传入start/stop..."
    exit 1
fi

# 2、根据参数匹配启动/停止
case $1 in
"start")
    pid=$(ps -ef | grep superset | grep -v grep | awk '{print $2}')
    if [ -n "$pid" ]; then
        echo "superset已经启动..."
    else
        source /opt/module/miniconda3/bin/activate superset
        if gunicorn --workers 5 --timeout 120 --bind hadoop102:8787 "superset.app:create_app()" --daemon; then
            echo "superset启动成功..."
        else
            echo "superset启动失败，请检查配置和日志..."
        fi
    fi
    ;;
"stop")
    pid=$(ps -ef | grep superset | grep -v grep | awk '{print $2}')
    if [ -n "$pid" ]; then
        if kill -9 $pid; then
            echo "superset停止成功..."
        else
            echo "superset停止失败，请手动检查并终止进程..."
        fi
    else
        echo "superset未启动..."
    fi
    ;;
*)
    echo "参数输入错误..."
    exit 1
    ;;
esac